package com.yswee.framework;

import com.yswee.framework.common.cache.image.ImageFetcher;
import com.yswee.framework.utils.OSUtils;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

public class Application extends android.app.Application {

	protected static Application instance;
	public static Application get() {
		return instance;
	}
	
	protected AppConfigure mConfigure;
	
	public AppConfigure getAppConfigure() {
		return mConfigure;
	}
	
	public boolean getZoomImage() {
		return true;
	}
	
	public Application() {
		instance = this;
		mConfigure = new AppConfigure();
	}
	
	@Override
	public void onCreate() {
		super.onCreate();
		OSUtils.closeAndroidPDialog();
		initException();
		ImageFetcher.get();
		clearCache();
	}
	
	@Override
	public void onTerminate() {
		super.onTerminate();
		exit();
	}
	
	public void exit() {
		
	}
	
	public void sendLocalBroadcast(Intent intent) {
        LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent);
    }
    
    public void unregisterLocalReceiver(BroadcastReceiver receiver) {
        LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
    }
	
    public void registerLocalReceiver(BroadcastReceiver receiver, IntentFilter filter) {
        LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter);
    }


	/**
	 * 获取发生crash时弹出的toast提示语
	 * @return
	 */
	public String getCrashToastText() {
		return "";
	}
	
	/**
	 * 上传crash日志
	 * @param filePath
	 * @param crashInfo
	 */
	public void uploadCrashLog(String filePath, String crashInfo) {
		
	}

	protected void initException() {
		CrashHandler.get();  
	}
	
	protected void clearCache() {
		new Thread(new Runnable() {
			@Override
			public void run() {
//				DataBaseAdapter.get().clearTableStrategyReadHistory();
//				FileUtils.removeFolder(Application.get(), FileUtils.getCachePath() + 
//						File.separator + FileUtils.PHOTOCACHEPATH);
//				FileUtils.removeFolder(Application.get(), FileUtils.getCachePath() + 
//						File.separator + FileUtils.VIDEOCACHEPATH);
			}
		}).run();
	}
	
}
